package edu.cuit.svsp.controller;

import edu.cuit.svsp.request.ResponseResult;
import edu.cuit.svsp.service.LikeService;
import edu.cuit.svsp.util.JWTUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @className: LikeController
 * @author: pjy
 * @description: 喜欢控制器
 * @date: 2024/7/6
 */
@RestController
@RequestMapping("/like")
public class LikeController {
    @Resource
    private LikeService likeService;


    // 更新喜欢
    @GetMapping("/update/{isUp}/{vid}")
    public ResponseResult updateLike(@PathVariable("isUp") boolean isUp, @PathVariable("vid") Integer vid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        return new ResponseResult(HttpStatus.OK.value(), "success", likeService.updateLike(isUp, vid, uid));
    }
    // 查询喜欢
    @GetMapping("/findByVid/{vid}")
    public ResponseResult findLike(@PathVariable("vid") Integer vid, HttpServletRequest request){
        int uid = JWTUtil.getuid(request.getHeader("Authorization"));
        return new ResponseResult(HttpStatus.OK.value(), "success", likeService.findLike(vid, uid));
    }
}
